<template>
  <div>
    <div class="dy-container">
      <!-- 图标 -->
      <div class="dy-header">
        <img src="../../assets/img/logo.png" alt />
      </div>

      <div>
        <!-- //注册 -->
        <!-- 输入框 -->
        <div class="dy-inp">
          <input type="text" placeholder="请输入手机号" v-model="getInfo.mobile"/>
          <div v-if="!timebool" @click="get">获取验证码</div>
          <div v-if="timebool" style="color:#ccc">获取验证码 {{time}}</div>
        </div>
        <!-- 输入框 -->
        <div class="dy-inp">
          <input type="text" placeholder="请输入短信验证码" v-model="getInfo.code" @focus="active=2" @blur="active=''"/>
        </div>

        <!-- 找回密码，登录注册切换 -->
        <div class="dy-mi">
          <span>*未注册的手机号将自动注册</span>
          <span @click="deng">注册/验证码登录</span>
        </div>

        <!-- 登录 -->
        <button class="dy-btn" @click="register">登录</button>
      </div>
    </div>
  </div>
</template>

<script>
import {Sms,SmsLogin} from '../../request/http'
export default {
  name: "",
  data() {
    return {
      getInfo:{
          mobile:"",
          code:"",
          sms_type:"login"
      },
      active:"",
      showOther:false,
      time:60,
      timebool:false,
      type:2
    };
  },
  props: [],
  components: {},
  mounted() {},
  methods: {
    deng(){
        this.$router.push({path:'/login'})
    },
    get(){
        var dy_reg=/^1[345678]\d{9}$/
        if(!dy_reg.test(this.getInfo.mobile)){
            this.$toast("手机号码格式不正确")
            return false
        }
        let obj={
            mobile:this.getInfo.mobile,
            sms_type:this.getInfo.sms_type
        }
        Sms(obj).then(res=>{
          console.log(res)
          this.timebool=true
            this.time=60
            let _this=this
            var timer=setInterval(() => {
                _this.time--;
                if(_this.time<=0){
                    _this.timebool=false
                    clearInterval(timer)
                }
            }, 1000);
        })
    },
    register(){
        if(this.getInfo.mobile=="" || this.getInfo.code==""){
            this.$toast("号码格式不正确")
            return false
        }
        
        let obj={
          mobile:this.getInfo.mobile,
          sms_code:this.getInfo.code,
          type:this.type
        }
        SmsLogin(obj).then(res=>{
          console.log(res)
          localStorage.setItem("adminToken",res.remember_token)
          localStorage.setItem("user_id",res.id)
          if(res.is_new==1){
            this.$store.commit("smslogin",{
              mobile:this.getInfo.mobile,
              sms_code:this.getInfo.code,
            })
            this.$router.push("/pass")
          }
        })
    }
  }
};
</script>

<style scoped>
.dy-container {
  width: 100%;
  height: 650px;
  background: #fff;
  padding: 0px 20px;
  box-sizing: border-box;
}
.dy-header {
  width: 100%;
  height: 150px;
  /* background: #000; */
  text-align: center;
  line-height: 200px;
}
.dy-header > img {
  width: 246px;
  height: 51px;
}
.dy-inp {
  height: 13.33333vw;
  background-color: #fff;
  border-bottom: 1px solid #f1f1f1;
  /* padding: 0 20px; */
  position: relative;
}
.dy-inp > input {
  box-sizing: border-box;
  padding: 0.4rem 0;
  padding: 4vw 0;
  border: 0;
  /* width: 7.2rem; */
  width: 72vw;
  height: 100%;
  font-size: 0.4rem;
  font-size: 4vw;
  font-family: PingFangSC-Regular;
  font-weight: 400;
  line-height: 0.53333rem;
  line-height: 5.33333vw;
  float: left;
  outline: none;
}
.dy-inp>div{
    color: #fd5d0b;
    position: absolute;
    top: 15px;
    right: 0;
}
.dy-mi {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  color: #999999;
}
.dy-btn {
  width: 98%;
  height: 45px;
  border-radius: 25px;
  border: none;
  outline: none;
  background: linear-gradient(to right, rgb(240, 163, 91), #fd5d0b);
  color: #fff;
  font-size: 14px;
  margin-top: 50px;
}
</style>